﻿SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
CREATE TABLE dbo.bht_ValidateColumnValidators
	(
	ValidatorId int NOT NULL IDENTITY (1, 1),
	InstanceClass nvarchar(200) NOT NULL,
	ExampleConfiguration nvarchar(MAX) NOT NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.bht_ValidateColumnValidators ADD CONSTRAINT
	PK_bht_ValidateColumnValidators PRIMARY KEY CLUSTERED 
	(
	ValidatorId
	) ON [PRIMARY]

GO
CREATE TABLE dbo.bht_ValidateColumnValidatorConfig
	(
	ValidatorId int NOT NULL,
	ColumnId int NOT NULL,
	XmlConfiguration nvarchar(MAX) NOT NULL
	)  ON [PRIMARY]

GO
ALTER TABLE dbo.bht_ValidateColumnValidatorConfig ADD CONSTRAINT
	FK_bht_ValidateColumnValidatorConfig_bht_ValidateColumnValidators FOREIGN KEY
	(
	ValidatorId
	) REFERENCES dbo.bht_ValidateColumnValidators
	(
	ValidatorId
	) ON UPDATE  CASCADE 
	 ON DELETE  CASCADE 
	
GO

CREATE PROCEDURE [dbo].[bhp_NemoColumnValidators] (
	@ColumnId	INT
)
AS
BEGIN

	SELECT
		cv.ColumnId,
		v.ValidatorId,
		v.InstanceClass,
		cv.XmlConfiguration
	FROM
		bht_ValidateColumnValidators v
		INNER JOIN bht_ValidateColumnValidatorConfig cv ON v.ValidatorId = cv.ValidatorId
	WHERE
		cv.ColumnId = @ColumnId	

END


GO

INSERT INTO bht_ValidateColumnValidators (InstanceClass, ExampleConfiguration) VALUES ('blackhouse.WebNemo.Web.Validators.ImageValidator, blackhouse.WebNemo.Web', '<?xml version="1.0" encoding="utf-16"?>
<ImageValidator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <AllowExtensions>
    <string>jpg</string>
    <string>png</string>
    <string>gif</string>
  </AllowExtensions>
  <MinimumSize>
    <Width>0</Width>
    <Height>0</Height>
  </MinimumSize>
</ImageValidator>')